import { Store, useStore } from 'vuex';

type StoreType = Store<UserData>;

interface UserData {
  token: string;
  username: string;
  email: string;
  id: number,
  followersCount: number;
  avatar: string;
}

export const handleProfile = async (store: StoreType, userData: UserData) => {
  const { token, username, email, id, followersCount, avatar } = userData;
  await store.dispatch('setUserInfo', { username, email, id, avatar, followersCount });
  sessionStorage.setItem('userInfo', JSON.stringify({ username, email, id, avatar, followersCount }));
  localStorage.setItem('token', token);
};